package com.yc.ycpaimon.ui.main

import android.content.Context
import android.content.Intent
import com.yc.jetpacklib.utils.YcSwitchFragmentUtil
import com.yc.ycpaimon.R
import com.yc.ycpaimon.base.BaseActivity
import com.yc.ycpaimon.databinding.MainActivityBinding


class MainActivity : BaseActivity<MainActivityBinding>(MainActivityBinding::inflate) {
    companion object {
        @JvmStatic
        fun newInstance(context: Context) {
            context.startActivity(Intent(context, MainActivity::class.java))
        }
    }

    private val mSwitchFragment by lazy { YcSwitchFragmentUtil() }
    override fun MainActivityBinding.initView() {
        bottomNavigationView.itemIconTintList = null
        mSwitchFragment.setFragments(
            mapOf(
                R.id.homeFragmentMenu to MainHomeFragment(),
                R.id.utilFragmentMenu to MainUtilFragment(),
                R.id.deviceFragmentMenu to MainMineFragment()
            )
        )
        mSwitchFragment.showFirstFragment(
            supportFragmentManager,
            R.id.fragmentContainer,
            R.id.homeFragmentMenu
        )
        bottomNavigationView.setOnItemSelectedListener {
            return@setOnItemSelectedListener if (mSwitchFragment.switchFragment(it.itemId)) {
                it.isChecked = true
                true
            } else {
                false
            }
        }
    }
}